package com.zoo.diannaopeijian.service.impl;

import com.zoo.diannaopeijian.common.page.Page;
import com.zoo.diannaopeijian.common.util.CheckUtil;
import com.zoo.diannaopeijian.domain.ComponentParameterDetail;
import com.zoo.diannaopeijian.mapper.ComponentParameterDetailMapper;
import com.zoo.diannaopeijian.service.ComponentParameterDetailService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 配件参数细节服务实现类
 */
@Service
public class ComponentParameterDetailServiceImpl implements ComponentParameterDetailService {
    @Resource
    private ComponentParameterDetailMapper componentParameterDetailMapper;

    @Override
    public boolean addComponentParameterDetail(ComponentParameterDetail componentParameterDetail) {
        if (CheckUtil.allNullBeanCheck(componentParameterDetail)) {
            return true;
        }
        return componentParameterDetailMapper.insertSelective(componentParameterDetail) == 1;
    }

    @Override
    public boolean updateComponentParameterDetail(ComponentParameterDetail componentParameterDetail) {
        if (CheckUtil.allNullBeanCheck(componentParameterDetail)) {
            return true;
        }
        return componentParameterDetailMapper.updateByPrimaryKeySelective(componentParameterDetail) == 1;
    }

    @Override
    public boolean deleteComponentParameterDetailById(Integer componentParameterDetailId) {
        if (componentParameterDetailId == null) {
            throw new NullPointerException();
        }
        return componentParameterDetailMapper.deleteByPrimaryKey(componentParameterDetailId) == 1;
    }

    @Override
    public List<ComponentParameterDetail> getComponentParameterDetail(ComponentParameterDetail componentParameterDetail) {
        return componentParameterDetailMapper.select(componentParameterDetail);
    }

    @Override
    public List<ComponentParameterDetail> getComponentParameterDetailWithPage(ComponentParameterDetail componentParameterDetail, Page page) {
        if (page != null) {
            page.onPage();
        }

        return getComponentParameterDetail(componentParameterDetail);
    }

}
